home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / MorphOS / tictactoe-1.2.1 / line_o_s.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-22  |  1.4 KB  |  82 lines

  1. #include "scores.h"
  2. #include "messages.h"
  3. #include "line_o_s.h"
  4.  
  5. int col_possible(int row, int col, int who) {
  6.     int y, score=0;
  7.     for(y=0; y<SIZE; y++) {
  8.         if(y==row)
  9.             continue;
  10.         if(board[y][col]==-who)
  11.             return 0;
  12.         if(!board[y][col])
  13.             continue;
  14.         if(row > y)
  15.             score+=SIZE-(row-y);
  16.         else
  17.             score+=SIZE-(y-row);
  18.     }
  19.     return score?score+LOS_SCORE:0;
  20. }
  21.  
  22. int row_possible(int row, int col, int who) {
  23.     int x, score=0;
  24.     for(x=0; x<SIZE; x++) {
  25.         if(x==col)
  26.             continue;
  27.         if(board[row][x]==-who)
  28.             return 0;
  29.         if(!board[row][x])
  30.             continue;
  31.         if(col > x)
  32.             score+=SIZE-(col-x);
  33.         else
  34.             score+=SIZE-(x-col);
  35.     }
  36.     return score?score+LOS_SCORE:0;
  37. }
  38.  
  39. int dia_possible(int row, int col, int who) {
  40.     int x, scorerd=0, scoreld=0;
  41.  
  42.     if(row!=col && row!=SIZE-1-col)    /* point not on diagonal */
  43.         return 0;
  44.     
  45.     if(row==col)            /* Going right-down */
  46.         for(x=0; x<SIZE; x++) {
  47.             if(x==row && x==col)
  48.                 continue;
  49.             if(board[x][x]==-who) {
  50.                 scorerd=0;
  51.                 break;
  52.             }
  53.             if(!board[x][x])
  54.                 continue;
  55.             if(row>x)
  56.                 scorerd+=SIZE-(row-x);
  57.             else
  58.                 scorerd+=SIZE-(x-row);
  59.         }
  60.     if(row==SIZE-1-col)             /* Going left-down */
  61.         for(x=0; x<SIZE; x++) {
  62.             if(x==row && SIZE-1-x==col)
  63.                 continue;
  64.             if(board[x][SIZE-1-x]==-who) {
  65.                 scoreld=0;
  66.                 break;
  67.             }
  68.             if(!board[x][SIZE-1-x])
  69.                 continue;
  70.             if(row>x)
  71.                 scoreld+=SIZE-(row-x);
  72.             else
  73.                 scoreld+=SIZE-(x-row);
  74.         }
  75.  
  76.     scorerd += scorerd?LOS_SCORE:0;
  77.     scoreld += scoreld?LOS_SCORE:0;
  78.  
  79.     return scorerd+scoreld;
  80. }
  81.  
  82.